import Vue from 'vue';
import VueRouter, { RouteConfig } from 'vue-router';
import { IndexRouter } from './modules/IndexRouter';
import { LoginRouter } from './modules/LoginRouter'
Vue.use(VueRouter);

// //解决重复点击路由报错的bug
// //获取原型对象上的push函数
// const originalPush = VueRouter.prototype.push;
// //修改原型对象上的push方法
// VueRouter.prototype.push = function push(location:any) {
//   return originalPush.call(this, location).catch((err:any) => err)
// }

export const routes: RouteConfig[] = [
  {
    path: '',
    redirect:'/login'
  },
  LoginRouter,
  IndexRouter
];

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
});

router.beforeEach((to, from, next) => {
  //路由发生改变修改页面title
  if (to.matched[0].meta.title) {
    document.title = to.matched[0].meta.title;
  }
  next();
})
export default router;

